package cn.eoneplus.mes.ui.module.verification.${classname};

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;

import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import com.afollestad.materialdialogs.MaterialDialog;

import java.util.List;

import cn.eoneplus.app.common.base.BaseActivity;
import cn.eoneplus.app.common.binding.command.BindingConsumer;
import cn.eoneplus.app.common.bus.Messenger;
import cn.eoneplus.app.common.my.MyBroadcastReceiver;
import cn.eoneplus.app.common.util.MaterialDialogUtil;
import cn.eoneplus.app.common.util.StringUtil;
import cn.eoneplus.mes.R;
import cn.eoneplus.mes.app.AppViewModelFactory;
import cn.eoneplus.mes.constant.AppConstant;
import cn.eoneplus.mes.databinding.ActivityVerification${ClassName}Binding;
import cn.eoneplus.mes.dto.onlinewms.shelf.WmsShelfTopicMsgDTO;
import cn.eoneplus.mes.dto.verification.${classname}.${InfoEntity};
import cn.eoneplus.mes.util.AppCommonUtil;
import cn.eoneplus.mes.util.BroadcastReceiverUtil;
import cn.eoneplus.mes.util.IntentUtil;

/**
 * Activity ${projectName}功能页面
 */
public class ${ClassName}Activity extends BaseActivity<ActivityVerification${ClassName}Binding, ${ClassName}ViewModel>{
    private MaterialDialog.Builder builder;
    <#if isBoundle>
    // DTO信息
    // private ${InfoEntity} ${infoEntity};

    /**
     * 接收传值 实体名称需要
     */
    @Override
    public void initParam(){
       Bundle mBundle=getIntent().getExtras();
       if(mBundle!=null){
            // ${infoEntity} = (${InfoEntity})mBundle.getSerializable("${infoEntity}");
       }
    }
    </#if>
    <#if isCardView>
    private ${ClassName}RecyclerViewBindingAdapter adapter=new ${ClassName}RecyclerViewBindingAdapter();
    </#if>


    @Override
    public int initContentView(Bundle savedInstanceState){
       return R.layout.activity_verification_${class_name};
    }

    @Override
    public int initVariableId(){
       return cn.eoneplus.mes.BR.viewModel;
    }

    @Override
    public ${ClassName}ViewModel initViewModel(){
       AppViewModelFactory factory=AppViewModelFactory.getInstance(getApplication());
       return ViewModelProviders.of(this,factory).get(${ClassName}ViewModel.class);
    }

    @Override
    public void initViewObservable(){
        // 消息对话框
        viewModel.infoDialogLiveData.observe(this,new Observer<List<String>>(){
            @Override
            public void onChanged(List<String> configList){
                MaterialDialogUtil.showBasicDialogNoCancel(${ClassName}Activity.this,
                configList.get(0),
                configList.get(1))
                .showListener(new DialogInterface.OnShowListener(){
                    @Override
                    public void onShow(DialogInterface dialog){
                        viewModel.isShowDialog=true;
                    }
                })
                .dismissListener(new DialogInterface.OnDismissListener(){
                    @Override
                    public void onDismiss(DialogInterface dialog){
                        viewModel.isShowDialog=false;
                    }
                })
                .show();
            }
            });
    }

    <#if isScan>
    /**
    * 接收扫描值
    */
    @Override
    public MyBroadcastReceiver initMyBroadcastReceiver(){
       return BroadcastReceiverUtil.generateCommonBroadcastReceiver(new MyBroadcastReceiver.MyBroadcastReceiverAction(){
            @Override
            public void call(Context context,Intent intent){
                if(builder!=null)builder.show().dismiss();
                String scanValue=BroadcastReceiverUtil.getScanValue(intent);
                if(StringUtil.isNotTrimEmpty(scanValue)){
                    viewModel.setErrorInfo("");
                    viewModel.receiveScanValue(scanValue.trim());
                }
            }
       });
    }
    </#if>

    @Override
    public void initData(){
        <#if isBoundle>
        viewModel.setInitData(${infoEntity});
        </#if>
        <#if isCardView>
        binding.setAdapter(adapter);
        </#if>
        super.initData();
    }

    @Override
    public IntentFilter initIntentFilter(){
        return IntentUtil.generateCommonIntentFilter();
    }

    @Override
    public boolean isAllDeviceFeedback(){
        return true;
    }

    @Override
    public void autoLogout(){
       AppCommonUtil.logoutApp(this);
    }
}